#include "pieces.h"
#include <stdlib.h>
#include <time.h>
#include <stdio.h>


char SPiece[MAX_PIECE][4][16] =
{
	//piece 1 : carre
	{
		{'0','0','0','0',
		 '0','1','1','0',
		 '0','1','1','0',
		 '0','0','0','0'},

		{'0','0','0','0',
		 '0','1','1','0',
		 '0','1','1','0',
		 '0','0','0','0'},

		{'0','0','0','0',
		 '0','1','1','0',
		 '0','1','1','0',
		 '0','0','0','0'},

		{'0','0','0','0',
		 '0','1','1','0',
		 '0','1','1','0',
		 '0','0','0','0'}
	},

	//piece 2 : barre
	{
		{'0','0','0','0',
		 '2','2','2','2',
		 '0','0','0','0',
		 '0','0','0','0'},

		{'0','2','0','0',
		 '0','2','0','0',
		 '0','2','0','0',
		 '0','2','0','0'},

		{'0','0','0','0',
		 '2','2','2','2',
		 '0','0','0','0',
		 '0','0','0','0'},

		{'0','2','0','0',
		 '0','2','0','0',
		 '0','2','0','0',
		 '0','2','0','0'}
	},

	//piece 3 : zigzag droite
	{
		{'0','0','0','0',
		 '0','0','3','3',
		 '0','3','3','0',
		 '0','0','0','0'},

		{'0','0','0','0',
		 '0','0','3','0',
		 '0','0','3','3',
		 '0','0','0','3'},

		{'0','0','0','0',
		 '0','0','3','3',
		 '0','3','3','0',
		 '0','0','0','0',},

		{'0','0','0','0',
		 '0','0','3','0',
		 '0','0','3','3',
		 '0','0','0','3'}
	},

	//piece '4' : zigzag gauche
	{
		{'0','0','0','0',
		 '0','4','4','0',
		 '0','0','4','4',
		 '0','0','0','0'},

		{'0','0','0','0',
		 '0','0','0','4',
		 '0','0','4','4',
		 '0','0','4','0'},

		{'0','0','0','0',
		 '0','4','4','0',
		 '0','0','4','4',
		 '0','0','0','0'},

		{'0','0','0','0',
		 '0','0','0','4',
		 '0','0','4','4',
		 '0','0','4','0'}
	},

	// piece 5 : L droite
	{
		{'0','0','0','0',
		 '0','5','5','5',
		 '0','5','0','0',
		 '0','0','0','0'},

		{'0','0','0','0',
		 '5','5','0','0',
		 '0','5','0','0',
		 '0','5','0','0'},

		{'0','0','0','0',
		 '0','0','0','5',
		 '0','5','5','5',
		 '0','0','0','0'},

		{'0','0','5','0',
		 '0','0','5','0',
		 '0','0','5','5',
		 '0','0','0','0'}
	},

	// piece 6 : L gauche
	{
		{'0','0','0','0',
		 '6','0','0','0',
		 '6','6','6','0',
		 '0','0','0','0'},

		{'0','0','0','0',
		 '0','6','6','0',
		 '0','6','0','0',
		 '0','6','0','0'},

		{'0','0','0','0',
		 '0','6','6','6',
		 '0','0','0','6',
		 '0','0','0','0'},

		{'0','0','6','0',
		 '0','0','6','0',
		 '0','6','6','0',
		 '0','0','0','0'}
	},

	// piece 7 : T
	{
		{'0','0','0','0',
		 '0','7','7','7',
		 '0','0','7','0',
		 '0','0','0','0'},

		{'0','0','7','0',
		 '0','7','7','0',
		 '0','0','7','0',
		 '0','0','0','0'},

		{'0','0','7','0',
		 '0','7','7','7',
		 '0','0','0','0',
		 '0','0','0','0'},

		{'0','0','7','0',
		 '0','0','7','7',
		 '0','0','7','0',
		 '0','0','0','0'}
	}
};



static int Random_0a6()
{
    return (rand()%7);
}


int tire_numPiece()
{
    int nb_alea;
    nb_alea = Random_0a6();
    return nb_alea;
}


bool estOccupee(int numPiece, int rotation, int px, int py)
{
    if (SPiece[numPiece][rotation][py*4+px] == '0')
    {
        return false;
    }
    else
    {
        return true;
    }
}


